package view

import (
	"fmt"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/util/gconv"
	"miaoyu/internal/utility"
)

// CommonBuildIn 视图自定义方法管理对象
type commonBuildIn struct {
	httpRequest *ghttp.Request
}

// BuildUrlByKey 内置函数引进测试
func (s *commonBuildIn) BuildUrlByKey(key string, anyVar ...interface{}) string {
	//url := router.GetRouteByKey(key)
	fmt.Println("url变量测试", anyVar)
	params := g.MapStrAny{}
	var keys string
	for index, val := range anyVar {
		if index%2 == 0 {
			keys = gconv.String(val)
			params[keys] = 1
		} else {
			params[keys] = val
		}
	}

	str := utility.UrlBuild(key, params)
	return str
}

// GetUrlByKey 内置函数引进测试
func (s *commonBuildIn) GetUrlByKey(key string) string {
	//url := router.GetRouteByKey(key)
	str := utility.GetRouteByKey(key)
	return str
}

// GetVarByKey 内置函数引进测试
func (s *commonBuildIn) GetVarByKey(key string, anyVar ...interface{}) string {
	//url := router.GetRouteByKey(key)
	for _, val := range anyVar {
		fmt.Println("echo", val)
	}
	return key
}
